<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends BaseController {
    public function index($username='', $p='') {
		$data = D('Home/User')->_lists($username, $p);
		$this->assign('data', $data);
    	$this->display();
    }

    public function edit($id='') {
		if(IS_POST) {
			$post = I('post.');
			if(empty($post['password'])) { unset($post['password']); }
			$R = D('Home/User')->update($post);
			if($R['e'] == -1) {
				$this->error($R['info']);
			}
			$this->success('操作成功', U('index'));
		} else {
			$data = M('user')->where(array('is_delete' => 1))->find($id);
			$this->assign('data', $data);
			$this->display();
		}
    }

    public function del($id) {
    	if($id == 1) {
    		$this->error('系统管理员不能删除');
    	}
    	if(M('user')->where(array('id' => $id))->save(array('is_delete' => -1)) === false){
    		$this->error('删除失败');
    	}
    	$this->success('操作成功');
    }
}